<?php

namespace App\B2BProject\Custom\Business;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Builder;

/**
 * Class Brand
 *
 * 品牌
 *
 * @package App\B2BProject\Custom\Business
 */
class Brand extends Model
{
    protected $guarded = ['created_at', 'updated_at'];

    /**
     * 查询允许展示的品牌
     *
     * @param Builder $query
     *
     * @return $this
     */
    public function scopeDisplay(Builder $query)
    {
        return $query->where('display', true);
    }

    /**
     * 查询被推荐的品牌
     *
     * @param Builder $query
     *
     * @return $this
     */
    public function scopeRecommend(Builder $query)
    {
        return $query->where('recommend', true);
    }

    public function categories()
    {
        return $this->belongsToMany('App\B2BProject\Custom\Business\GoodsCategory');
    }

    public function goods()
    {
        return $this->hasMany('App\B2BProject\Custom\Business\Brand', 'brand_id', 'id');
    }
}
